{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8d2abfb5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "data=pd.read_csv('future3yue.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fe134967",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数据时间</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021/9/1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021/9/2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021/9/3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021/9/4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021/9/5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>2021/11/26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>2021/11/27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>2021/11/28</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>2021/11/29</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>2021/11/30</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>91 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          数据时间\n",
       "0     2021/9/1\n",
       "1     2021/9/2\n",
       "2     2021/9/3\n",
       "3     2021/9/4\n",
       "4     2021/9/5\n",
       "..         ...\n",
       "86  2021/11/26\n",
       "87  2021/11/27\n",
       "88  2021/11/28\n",
       "89  2021/11/29\n",
       "90  2021/11/30\n",
       "\n",
       "[91 rows x 1 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a367d78e",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['数据时间'] = pd.to_datetime(data['数据时间'])\n",
    "data['月'] = data['数据时间'].dt.month \n",
    "data['天'] = data['数据时间'].dt.day\n",
    "data['小时'] = data['数据时间'].dt.hour\n",
    "data['一年第几天'] = data['数据时间'].dt.dayofyear\n",
    "data['一年第几周'] = data['数据时间'].dt.isocalendar().week\n",
    "data['weekday'] = data['数据时间'].dt.weekday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "fd95e8bb",
   "metadata": {},
   "outputs": [],
   "source": [
    "period_dict ={\n",
    "            23: '深夜', 0: '深夜', 1: '深夜',\n",
    "            2: '凌晨', 3: '凌晨', 4: '凌晨',\n",
    "            5: '早晨', 6: '早晨', 7: '早晨',\n",
    "            8: '上午', 9: '上午', 10: '上午', 11: '上午',\n",
    "            12: '中午', 13: '中午',\n",
    "            14: '下午', 15: '下午', 16: '下午', 17: '下午',\n",
    "            18: '傍晚',\n",
    "            19: '晚上', 20: '晚上', 21: '晚上', 22: '晚上',\n",
    "            }\n",
    "data['时间段']=data['小时'].map(period_dict)\n",
    "dict1 = {'深夜':1, '凌晨':2, '早晨':3, '上午':4, '中午':5, '下午':6, '傍晚':7, '晚上':8}\n",
    "data['时间段'] = data['时间段'].map(dict1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "05595dd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "season_dict = {\n",
    "                1: '春季', 2: '春季', 3: '春季',\n",
    "                4: '夏季', 5: '夏季', 6: '夏季',\n",
    "                7: '秋季', 8: '秋季', 9: '秋季',\n",
    "                10: '冬季', 11: '冬季', 12: '冬季',\n",
    "            }\n",
    "data['季节']=data['月'].map(season_dict)\n",
    "dict = {'春季':1,'夏季':2,'秋季':3,'冬季':4}\n",
    "data['季节'] = data['季节'].map(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "27d4c323",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['是否月初'] = data['数据时间'].apply(lambda x: x.is_month_start)\n",
    "# 是否月末\n",
    "data['是否月末'] = data['数据时间'].apply(lambda x: x.is_month_end)\n",
    "# 是否季节初\n",
    "data['是否季节初'] = data['数据时间'].apply(lambda x: x.is_quarter_start)\n",
    "# 是否季节末\n",
    "data['是否季节末'] = data['数据时间'].apply(lambda x: x.is_quarter_end)\n",
    "data['是否周末'] = data['数据时间'].apply(lambda x: True if x.dayofweek in [5, 6] else False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8260baaa",
   "metadata": {},
   "outputs": [],
   "source": [
    "data['是否月末'] = [int(i) for i in data['是否月末']]\n",
    "data['是否季节初'] = [int(i) for i in data['是否季节初']]\n",
    "data['是否季节末'] = [int(i) for i in data['是否季节末']]\n",
    "data['是否周末'] = [int(i) for i in data['是否周末']]\n",
    "data['是否月初'] = [int(i) for i in data['是否月初']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "03f2f4f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>数据时间</th>\n",
       "      <th>月</th>\n",
       "      <th>天</th>\n",
       "      <th>小时</th>\n",
       "      <th>一年第几天</th>\n",
       "      <th>一年第几周</th>\n",
       "      <th>weekday</th>\n",
       "      <th>时间段</th>\n",
       "      <th>季节</th>\n",
       "      <th>是否月初</th>\n",
       "      <th>是否月末</th>\n",
       "      <th>是否季节初</th>\n",
       "      <th>是否季节末</th>\n",
       "      <th>是否周末</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021-09-01</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>244</td>\n",
       "      <td>35</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021-09-02</td>\n",
       "      <td>9</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>245</td>\n",
       "      <td>35</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-09-03</td>\n",
       "      <td>9</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>246</td>\n",
       "      <td>35</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021-09-04</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>247</td>\n",
       "      <td>35</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021-09-05</td>\n",
       "      <td>9</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>248</td>\n",
       "      <td>35</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>2021-11-26</td>\n",
       "      <td>11</td>\n",
       "      <td>26</td>\n",
       "      <td>0</td>\n",
       "      <td>330</td>\n",
       "      <td>47</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>2021-11-27</td>\n",
       "      <td>11</td>\n",
       "      <td>27</td>\n",
       "      <td>0</td>\n",
       "      <td>331</td>\n",
       "      <td>47</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>2021-11-28</td>\n",
       "      <td>11</td>\n",
       "      <td>28</td>\n",
       "      <td>0</td>\n",
       "      <td>332</td>\n",
       "      <td>47</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>2021-11-29</td>\n",
       "      <td>11</td>\n",
       "      <td>29</td>\n",
       "      <td>0</td>\n",
       "      <td>333</td>\n",
       "      <td>48</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>2021-11-30</td>\n",
       "      <td>11</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>334</td>\n",
       "      <td>48</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>91 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         数据时间   月   天  小时  一年第几天  一年第几周  weekday  时间段  季节  是否月初  是否月末  是否季节初  \\\n",
       "0  2021-09-01   9   1   0    244     35        2    1   3     1     0      0   \n",
       "1  2021-09-02   9   2   0    245     35        3    1   3     0     0      0   \n",
       "2  2021-09-03   9   3   0    246     35        4    1   3     0     0      0   \n",
       "3  2021-09-04   9   4   0    247     35        5    1   3     0     0      0   \n",
       "4  2021-09-05   9   5   0    248     35        6    1   3     0     0      0   \n",
       "..        ...  ..  ..  ..    ...    ...      ...  ...  ..   ...   ...    ...   \n",
       "86 2021-11-26  11  26   0    330     47        4    1   4     0     0      0   \n",
       "87 2021-11-27  11  27   0    331     47        5    1   4     0     0      0   \n",
       "88 2021-11-28  11  28   0    332     47        6    1   4     0     0      0   \n",
       "89 2021-11-29  11  29   0    333     48        0    1   4     0     0      0   \n",
       "90 2021-11-30  11  30   0    334     48        1    1   4     0     1      0   \n",
       "\n",
       "    是否季节末  是否周末  \n",
       "0       0     0  \n",
       "1       0     0  \n",
       "2       0     0  \n",
       "3       0     1  \n",
       "4       0     1  \n",
       "..    ...   ...  \n",
       "86      0     0  \n",
       "87      0     1  \n",
       "88      0     1  \n",
       "89      0     0  \n",
       "90      0     0  \n",
       "\n",
       "[91 rows x 14 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "30497bb6",
   "metadata": {},
   "outputs": [],
   "source": [
    "#输出数据\n",
    "column=['数据时间','月', '天', '小时', '一年第几天', '一年第几周', 'weekday',\\\n",
    "                     '时间段', '季节', '是否月初','是否月末', '是否季节初', '是否季节末', '是否周末']\n",
    "future3yue_new=pd.DataFrame(columns=column,data=data)\n",
    "future3yue_new.to_csv('future3yue_new.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fcdba18f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         0\n",
       "1         0\n",
       "2         0\n",
       "3         0\n",
       "4         0\n",
       "         ..\n",
       "128539    1\n",
       "128540    1\n",
       "128541    1\n",
       "128542    1\n",
       "128543    1\n",
       "Name: weekday, Length: 128544, dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7d3e98d5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
